
<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item
        label="  文章标题:"
        prop="title"
      >
        <el-input v-model="ruleForm.title"></el-input>
      </el-form-item>
      <el-form-item
        label="  文章内容:"
        prop="body"
        value=""
      >
        <quill-editor
          v-model="ruleForm.articleBody"
          @blur="onblur"
        > </quill-editor>
        <span class="errorText">{{str}}</span>
      </el-form-item>
      <el-form-item label="视频地址:">
        <el-input v-model="ruleForm.videoURL"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'ArticlesAdd',
  components: {},
  data() {
    return {
      ruleForm: {
        title: '',
        articleBody: '',
        videoURL: ''
      },
      str: '',
      rules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() { },
  methods: {
    onblur() {
      if (this.ruleForm.articleBody.split(' ').join('').length === 0) {
        this.str = '请输入内容'
      } else {
        this.str = ''
        this.$emit('form-str', this.ruleForm)
        this.$emit('from-rules', this.rules)
        // console.log(this.ruleForm);
        // console.log(this.rules)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.errorText {
  color: #f56c6c;
}
</style>
